package com.llyb.controller;

import com.llyb.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingSearchRequest;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class RAGController {


    @Resource
    private ChatAssistant chatAssistant;

    @Resource
    private InMemoryEmbeddingStore<TextSegment> inMemoryEmbeddingStore;




    // http://localhost:9013/chatRag/chat1
    @GetMapping("/chatRag/chat1")
    public String chatRag() {

        Document document = FileSystemDocumentLoader.loadDocument("E:\\尚硅谷作业\\mywork\\myerror\\myerror.md");

        EmbeddingStoreIngestor.ingest(document,inMemoryEmbeddingStore);

        String chat = chatAssistant.chat("挑选一个认为最难的错误");

        System.out.println(chat);

        return chat;
    }

}
